home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Utilities / Catharsis / example / Example.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-05  |  6.0 KB  |  238 lines

  1. /*
  2.     Author:    J.v.d.Loo
  3.  
  4.     NOTE:    I have currently not installed the required header files.
  5.             I copied the whole archive to RAM: and compiled all there.
  6.  
  7.     USAGE:    1> example TimesNewRoman.font 15
  8. */
  9.  
  10. #include "RAM:Catharsis/include/catharsis.h"        /* Standard include file */
  11. #include "RAM:Catharsis/include/catharsisbase.h"    /* Standard include file */
  12. #include "RAM:Catharsis/clib/catharsis_protos.h"    /* Prototype */
  13. #include "RAM:Catharsis/pragma/catharsis_lib.h"        /* Pragma */
  14.  
  15. #include <graphics/view.h>
  16. #include <intuition/intuition.h>
  17. #include <utility/tagitem.h>
  18.  
  19. #include <pragma/exec_lib.h>
  20. #include <clib/exec_protos.h>
  21.  
  22. #include <pragma/graphics_lib.h>
  23. #include <clib/graphics_protos.h>
  24.  
  25. #include <pragma/intuition_lib.h>
  26. #include <clib/intuition_protos.h>
  27.  
  28. #include <pragma/diskfont_lib.h>
  29. #include <clib/diskfont_protos.h>
  30.  
  31. struct CatharsisBase *CatharsisBase;
  32. struct GfxBase *GfxBase;
  33. struct IntuitionBase *IntuitionBase;
  34. struct Library *DiskfontBase;
  35.  
  36. struct TextAttr TextFontAttr;
  37. struct TextFont *TextFont;
  38. struct TextFont *CatharsisFont;
  39.  
  40. struct NewWindow WinRec =
  41. {
  42.     0,0,
  43.     640,240,
  44.     -1,-1,
  45.     IDCMP_CLOSEWINDOW|IDCMP_INTUITICKS,
  46.     WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_RMBTRAP,
  47.     NULL,
  48.     NULL,
  49.     "Catharsis Example",
  50.     NULL,
  51.     NULL,
  52.     640,240,
  53.     -1,-1,
  54.     WBENCHSCREEN
  55. };
  56.  
  57. struct Window *Window;
  58.  
  59. UBYTE StrTxt1[] = "Going to create Catharsis-font, that takes its time...";
  60. UBYTE StrTxt2[] = "Done!";
  61.  
  62. UBYTE *StrTxts[3] =
  63. {
  64.     "The quick brown fox jumped over the lazy dog  ",    // until the hunter shot
  65.     "0 1 2 3 4 5 6 7 8 9   ",
  66.     "% & ! § å ° ® þ ¤ ¡ ø £ ð æ   "
  67. };
  68.  
  69. unsigned long ReadPensCol( ULONG pen)
  70. {
  71.     ULONG table[3], val, val1, help;
  72.     UBYTE ms;
  73.  
  74.     if (GfxBase->LibNode.lib_Version > 38)    // OS 3 or better?
  75.     {
  76.         GetRGB32( IntuitionBase->ActiveScreen->ViewPort.ColorMap, pen, 1, (ULONG *) &table);
  77.         ms = table[0] >> 24;
  78.         val = ms << 16;
  79.  
  80.         ms = table[1] >> 24;
  81.         val |= ms << 8;
  82.  
  83.         ms = table[2] >> 24;
  84.         val |= ms;
  85.     }
  86.     else
  87.     {
  88.         val = GetRGB4( IntuitionBase->ActiveScreen->ViewPort.ColorMap, pen);    // OS 1.2 through 2.1 compatible...
  89.         help = ((val & 0xF00) >> 8);
  90.         help |= (help << 4);
  91.         val1 = help << 16;
  92.  
  93.         help = ((val & 0xF0) >> 4);
  94.         help |= (help << 4);
  95.         val1 |= (help << 8);
  96.  
  97.         help = (val & 0xF);
  98.         help |= (help << 4);
  99.         val1 |= help;
  100.  
  101.         val = val1;
  102.     }
  103.  
  104.     return val;
  105. }
  106.  
  107.  
  108. int main( unsigned long argc, unsigned char **argv)
  109. {
  110.     ULONG bg, fg, cts, os[3], pen, penreserved, cycle, imsgclass, status;
  111.     struct IntuiMessage *imsg;
  112.     struct TagItem tags[2];
  113.     
  114.  
  115.     if ( (CatharsisBase = (struct CatharsisBase *) OpenLibrary( "catharsis.library", 1)) )
  116.     {
  117.         GfxBase = CatharsisBase->cts_GfxBase;
  118.         IntuitionBase = CatharsisBase->cts_IntuitionBase;
  119.  
  120.         bg  = ReadPensCol( 0);
  121.         fg  = ReadPensCol( 1);
  122.         cts = CatharsisColorValueA( bg, fg, &os[0], &os[1], &os[2]);
  123.         printf("BG: 0x%06lX, FG: 0x%06lX, Catharsis-Text-Color: 0x%06lX or RGB32: 0x%08lX, 0x%08lX, 0x%08lX\n", bg, fg, cts, os[0], os[1], os[2]);
  124.  
  125.         if ( (DiskfontBase = (struct Library *) OpenLibrary( "diskfont.library", 33)) )
  126.         {
  127.             if (argc > 2)
  128.             {
  129.                 TextFontAttr.ta_Name = argv[1];
  130.                 status = atoi( argv[2]);
  131.                 TextFontAttr.ta_YSize = status;
  132.                 TextFontAttr.ta_Style = NULL;
  133.                 TextFontAttr.ta_Flags = FPF_ROMFONT;
  134.                 if ( !(TextFont = OpenFont( &TextFontAttr)) || status != TextFont->tf_YSize)
  135.                 {
  136.                     if (TextFont)
  137.                         CloseFont( TextFont);
  138.                     TextFontAttr.ta_Flags = FPF_DISKFONT;
  139.                     TextFont = OpenDiskFont( &TextFontAttr)
  140.                 }
  141.  
  142.                 if (TextFont)
  143.                 {
  144.                     if ((Window = OpenWindow( &WinRec)) )
  145.                     {
  146.                         penreserved = -1L;
  147.  
  148.                         if (GfxBase->LibNode.lib_Version > 38)
  149.                         {
  150.                             tags[0].ti_Tag = OBP_Precision;
  151.                             tags[0].ti_Data = PRECISION_EXACT;
  152.                             tags[1].ti_Tag = TAG_DONE;
  153.  
  154.                             pen = ObtainBestPenA( Window->WScreen->ViewPort.ColorMap, os[0], os[1], os[2], tags);
  155.                             if (pen == -1L)
  156.                             {
  157.                                 pen = FindColor( Window->WScreen->ViewPort.ColorMap, os[0], os[1], os[2], -1);
  158.                             }
  159.                             else
  160.                             {
  161.                                 penreserved = pen;
  162.                             }
  163.                         }
  164.                         else
  165.                         {
  166.                             pen = 3;
  167.                         }
  168.  
  169.                         SetFont( Window->RPort, TextFont);
  170.                         SetAPen( Window->RPort, 1);
  171.                         SetDrMd( Window->RPort, JAM2);
  172.                         Move( Window->RPort, 10, Window->BorderTop + 8 + TextFont->tf_Baseline);
  173.                         Text( Window->RPort, StrTxt1, strlen (StrTxt1) );
  174.  
  175.                         if ( (CatharsisFont = OpenCatharsisFontA( TextFont)) )
  176.                         {
  177.                             Move( Window->RPort, 10, Window->BorderTop + 8 + TextFont->tf_Baseline + TextFont->tf_YSize + 4);
  178.                             Text( Window->RPort, StrTxt2, strlen (StrTxt2) );
  179.  
  180.                             cycle = NULL;
  181.                             status = -1;
  182.                             imsgclass = NULL;
  183.                             imsg = NULL;
  184.                             while (imsgclass != IDCMP_CLOSEWINDOW)
  185.                             {
  186.                                 WaitPort( Window->UserPort);
  187.                                 while ( (imsg = (struct IntuiMessage *) GetMsg( Window->UserPort)) )
  188.                                 {
  189.                                     imsgclass = imsg->Class;
  190.                                     ReplyMsg( (struct Message *) imsg);
  191.  
  192.                                     if (imsgclass == IDCMP_INTUITICKS)
  193.                                         cycle ++;
  194.                                     if ( cycle == 50)
  195.                                     {
  196.                                         cycle = 1;
  197.                                         status ++;
  198.                                         if (status > 2)
  199.                                             status = 0;
  200.                                         SetDrMd( Window->RPort, JAM2);
  201.                                         Move( Window->RPort, 10, Window->BorderTop + 8 + TextFont->tf_Baseline);
  202.                                         Text( Window->RPort, StrTxts[status], strlen (StrTxts[status]) );
  203.                                         Move( Window->RPort, 10, Window->BorderTop + 8 + TextFont->tf_Baseline + TextFont->tf_YSize + 4);
  204.                                         CatharsisTextA( Window->RPort, StrTxts[status], strlen (StrTxts[status]), pen, CatharsisFont);
  205.                                     }
  206.                                 }
  207.                             }
  208.                             CloseCatharsisFontA( CatharsisFont);
  209.                         }
  210.                         else
  211.                         {
  212.                             printf("Cannot open/create font!\n");
  213.                         }
  214.  
  215.                         if (penreserved != -1L)
  216.                             ReleasePen( Window->WScreen->ViewPort.ColorMap, penreserved);
  217.                         CloseWindow( Window);
  218.                     }
  219.                     else
  220.                     {
  221.                         printf("Cannot open a window of size 640x240 pixels!\n");
  222.                     }
  223.                     CloseFont( TextFont);
  224.                 }
  225.                 else
  226.                 {
  227.                     printf("Cannot open specified font »%s«, size %ld!\n", argv[1], status);
  228.                 }
  229.  
  230.             }
  231.  
  232.             CloseLibrary( DiskfontBase);
  233.         }
  234.         CloseLibrary( (struct Library *) CatharsisBase);
  235.     }
  236.     return 0;
  237. }
  238.